package com.atguigu.yygh.user.utils;

import com.atguigu.yygh.common.utils.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 杨林
 * @create 2022-11-15 19:36 星期二
 * description:
 */
//获取当前用户信息的工具类
public class AuthContextHolder {
    //获取当前用户id
    public static long getUserId(HttpServletRequest request){
        //从header中获取token
        String token = request.getHeader("token");
        //jwt在token中获取id
        Long userId = JwtHelper.getUserId(token);

        return userId;
    }

    //获取当前用户姓名
    public static String getUserName(HttpServletRequest request){
        //从header中获取token
        String token = request.getHeader("token");
        //从token中获取UserName
        String userName = JwtHelper.getUserName(token);
        return userName;
    }
}
